package test923;

import java.util.Random;
import java.util.Scanner;

public class five {
    public static void main(String[] args) {
        Random random = new Random();
        int targetNumber = random.nextInt(10) + 1; // 生成1到10之间的随机整数
        System.out.println("猜数字游戏开始！");

        Scanner scanner = new Scanner(System.in);
        int guess;
        int attempts = 0;

        do {
            System.out.print("请输入你猜测的数字（1到10之间）：");
            guess = scanner.nextInt();
            attempts++;

            if (guess > targetNumber) {
                System.out.println("猜大了！请继续尝试。");
            } else if (guess < targetNumber) {
                System.out.println("猜小了！请继续尝试。");
            } else {
                System.out.println("恭喜你，猜对了！");
                System.out.println("你总共猜了 " + attempts + " 次。");
            }
        } while (guess != targetNumber);

        System.out.println("游戏结束。");
    }
}
